#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main() {
  freopen("hopscotch.in", "r", stdin);
  freopen("hopscotch.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int R, C;

  cin >> R >> C;
  vector<string> g(R);
  vector<vector<LL>> dp(R, vector<LL>(C, 0));
  for (int i = 0; i < R; i++) {
    cin >> g[i];
  }
  dp[0][0] = 1;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      if (dp[i][j] == 0) {
        continue;
      }
      for (int k = i + 1; k < R; k++) {
        for (int l = j + 1; l < C; l++) {
          if (g[i][j] != g[k][l]) {
            dp[k][l] += dp[i][j];
          }
        }
      }
    }
  }
  cout << dp[R - 1][C - 1] << "\n";
  return 0;
}